
#include <string>
#include "regex_prefix_matcher.hpp"
#include "gtest/gtest.h"

using std::string;

struct MatchTest {
  string input;
  string match;
}; 

//
// Float number tests
//
TEST(RegexPrefixMatcherTests, FloatTests) {
  // Pairs (text, match)
  MatchTest floats_tests[] = {
    {"3.1415", "3.1415"},
    {".0e+3abc", ".0e+3"},
  };

  const char float_pattern[] = "[0-9]*\\.\\?[0-9]\\+\\([eE][-+]\\?[0-9]\\+\\)\\?";

  int n = sizeof(floats_tests) / sizeof(floats_tests[0]); 
  for (int i = 0; i < n; i++) {
    EXPECT_EQ(true, Matcher::prefixMatch(float_pattern, floats_tests[i].input))
      << "Test " << i << "/" << n << " failed";
    EXPECT_EQ(floats_tests[i].match.size(), Matcher::getLastMatchLength()) 
      << "Test " << i << "/" << n << " failed";
  }
}

//
// Int number tests
//
TEST(RegexPrefixMatcherTests, IntTests) {
  // Pairs (text, match)
  MatchTest int_tests[] = {
    {"0", "0"},
    {"0.3", "0"},
  };

  const char int_pattern[] = "[0-9]\\+";

  int n = sizeof(int_tests) / sizeof(int_tests[0]);
  for (int i = 0; i < n; i++) {
    EXPECT_EQ(true, Matcher::prefixMatch(int_pattern, int_tests[i].input))
      << "Test " << i << "/" << n << " failed";
    EXPECT_EQ(int_tests[i].match.size(), Matcher::getLastMatchLength()) 
      << "Test " << i << "/" << n << " failed";
  }
}

// Add here other tests
